<h2><?= $this->escape($this->element->getAttrib('title')) ?></h2>
<p class="description"><?= $this->escape($this->element->getAttrib('description')) ?></p>

<?php
	$value = $this->element->getValue();
	$name = $this->element->getName();
	$questions = $this->element->getAttrib('questions');
	$responses = $this->element->getAttrib('responses');
	$other = trim($this->element->getAttrib('response_na'));
?>

<table>
	<thead>
		<tr>
			<th>Pytanie</th>

			<?php foreach($responses as $weight=>$text) { ?>
			<th><?= $this->escape($text) ?></th>
			<?php } ?>

			<?php if ($other !== ''): ?>
			<th><?= $this->escape($other) ?></th>
			<?php endif; ?>
		</tr>
	</thead>
	<tbody>

		<?php foreach($questions as $id=>$question) { ?>
		<tr>
			<th scope="row"><?= $this->escape($question) ?></th>

			<?php foreach($responses as $weight=>$text) { ?>
			<th><input type="radio" title="<?= $this->escape($text) ?>" name="<?= $name.'['.$id.']' ?>" <?= (isset($value[$id]) && $value[$id] === (string)$weight) ? 'checked="checked"' : '' ?> value="<?= $weight ?>" /></th>
			<?php } ?>

			<?php if ($other !== ''): ?>
			<th><input type="radio" title="<?= $this->escape($other) ?>" name="<?= $name.'['.$id.']' ?>" <?= (isset($value[$id]) && $value[$id] === 'other') ? 'checked="checked"' : '' ?> value="other" /></th>
			<?php endif; ?>
		</tr>
		<?php } ?>

	</tbody>
</table>

